package com.leo;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @ClassName HyperlinkDemo
 * @Description 超链接
 * @Author wangss
 * @date 2020.05.18 22:27
 * @Version 1.0
 */
public class HyperlinkDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        VBox vBox = new VBox();

        final Hyperlink hyperlink = new Hyperlink("www.baidu.com", new Button("网址"));
        hyperlink.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                HostServices services = HyperlinkDemo.this.getHostServices();
                services.showDocument(hyperlink.getText());
            }
        });

        vBox.getChildren().add(hyperlink);

        Scene scene = new Scene(vBox);

        primaryStage.setScene(scene);
        primaryStage.setTitle("超链接");
        primaryStage.setWidth(500d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
